package com.zengguang.testkaoshi.services.impl;

import com.zengguang.testkaoshi.dao.TestAnswerDao;
import com.zengguang.testkaoshi.pojo.Testanswer;
import com.zengguang.testkaoshi.services.ITestAnswerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TestAnswerService implements ITestAnswerService {
    @Autowired
    private TestAnswerDao testAnswerDao;
    @Override
    public List<Testanswer> selectAllTestAnswer() {
       List<Testanswer> list=testAnswerDao.selectAllTestAnswer();
        return list;
    }
    //插入
    @Override
    public int insertTestanswer(Testanswer testanswer) {
        int returnInt=0;

            //2、数据添加
            int addClassInt=testAnswerDao.insertTestanswer(testanswer);
            //3、返回值设置
            returnInt=addClassInt;
        return returnInt;
    }
    //删除
    @Override
    public int deleteTestanswer(int testanswerid) {
        int isdel=0;
        try {
                isdel=testAnswerDao.deleteTestanswer(testanswerid);

        }catch (Exception ex){
            isdel=-1;
            System.out.println("删除试卷答题表执行SQL报错"+ex.getMessage());
        }

        return isdel;
    }

    //更新
    @Override
    public int updateTestanswer(Testanswer testanswer) {
        int isUpdate=0;
        try {
            isUpdate=testAnswerDao.updateTestanswer(testanswer);
        }catch (Exception ex){
            isUpdate=-1;
            //打印更新时报错的情况
            System.out.println("更新试卷答题表时执行SQL报错的原因为："+ex.getMessage());
        }
        return isUpdate;
    }
}
